
using System;
using System.Data;
using System.Data.OracleClient;
using System.Configuration;
using System.Windows.Forms;
namespace Reverso.DataObjects
{


	public class DBHelper
	{
		protected OracleConnection oConnection;

		public DBHelper ()
		{
			System.Configuration.Configuration config =
         ConfigurationManager.OpenExeConfiguration
                    (ConfigurationUserLevel.None);
			string connectionString = "Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST="+ config.AppSettings.Settings["Host"].Value + ")(PORT="+config.AppSettings.Settings["Porta"].Value+")))"+
					"(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME="+config.AppSettings.Settings["SID"].Value+")));"+
					"User Id="+ config.AppSettings.Settings["Usuario"].Value+ ";Password="+config.AppSettings.Settings["Senha"].Value+";";
			//string connectionString = "data source='HR/HR@NoteBookBob/XE;'";
			oConnection = new OracleConnection();
			oConnection.ConnectionString = connectionString;
			
		}
		public DataSet ExecutarConsulta(string SQL)
		{
			OracleCommand oCommand = new OracleCommand();
			oCommand.CommandType = CommandType.Text;
			oCommand.CommandText = SQL;
			oCommand.Connection = oConnection;
			DataSet oDataSet = new DataSet();
			
			OracleDataAdapter oAdapter = new OracleDataAdapter();
			oAdapter.SelectCommand = oCommand;
			
			try
			{
				oConnection.Open();
				oAdapter.Fill(oDataSet);
			
				return oDataSet;
			}
			catch(Exception e)
			{
				MessageBox.Show(e.Message);
				return null;
			}finally
			{
				oConnection.Close();
			}
			
				
				
		}
		
	}
}
